local blaze  = require "blaze"
local app = require "app"
local game = require "club.threecard.sudoku"

local TabHeaderList = require "ui.Common.TabHeaderList"
local MainTabBarItem = require "club.threecard.sudoku.ui.main.MainTabBarItem"

local M = game.ui.activity()

function M:ctor()
    self.res = "club.threecard.sudoku/ui/main.b:MainUI"
    self.tab_router_view = app.ui.create_router_view("/club.threecard.sudoku/main", 2)
    self.tab_headers = TabHeaderList.new(MainTabBarItem)
end

function M:on_injected(bind)
    self.tab_router_view:mount(self.tab_pages_root)
    self.tab_headers:set_parent(self.tab_headers_root)
end

function M:after_route_enter(to, from)
    self:super("after_route_enter", to, from)
    game.audio.post("main-theme")
    local route = to.matched[1]
    self.tab_headers:fill(route.children)
end

function M:before_route_update(to, from, next)
    self.tab_headers:before_route_update(to, from)
    self:super("before_route_update", to, from, next)
end

function M:on_release()
    self.tab_headers:release()
    self.tab_router_view:release()
end

return M